<?php
class Pages_Form_Page extends Zend_Form {
	public function init() {
		$this->setMethod('post');
		
		$locales = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOption('locales');
		$defaultLang = key($locales);
		
		$subFormName = new Zend_Form_SubForm();
        $subFormName->removeDecorator('Fieldset');
        $subFormDescription = new Zend_Form_SubForm();
        $subFormDescription->removeDecorator('Fieldset');
        $subFormKeywords = new Zend_Form_SubForm();
        $subFormKeywords->removeDecorator('Fieldset');
        
        foreach($locales as $lang=>$value) {
        	$title = new Zend_Form_Element_Text($lang);
        	$title->setLabel(strtoupper($lang) . ' ' . _('Title:'));
        	$title->setAttrib('maxlength', '255');
        	$title->addFilters(array('StringTrim','StripTags'));
			
			$description = new Zend_Form_Element_Textarea($lang);
			$description->setLabel(strtoupper($lang) . ' ' . _('Seo Description:'));
			$description->setAttrib('cols', '48');
			$description->setAttrib('rows', '8');
			$description->setFilters(array('StringTrim', 'StripTags'));
			
			$keywords = new Zend_Form_Element_Textarea($lang);
			$keywords->setLabel(strtoupper($lang) . ' ' . _('Seo Keywords:'));
			$keywords->setFilters(array('StringTrim', 'StripTags'));
			$keywords->setAttrib('cols', '48');
			$keywords->setAttrib('rows', '8');
			
			if($defaultLang == $lang) {
				$title->setRequired(true);
				$description->setRequired(true);
				$keywords->setRequired(true);
			}
			
			$subFormName->addElement($title);
			$subFormDescription->addElement($description);
			$subFormKeywords->addElement($keywords);
        	
        }
		
        $published = $this->createElement('radio','published');
		$published->setLabel(_('Published:'));
		$published->setSeparator(' ');
		$published->addMultiOptions(array('1'=>_('Yes'),'0'=>_('No')));
		$published->setValue('1');
		$published->setRequired(true);
		
		$show_content = $this->createElement('radio','show_content');
		$show_content->setLabel(_('Show content:'));
		$show_content->setSeparator(' ');
		$show_content->addMultiOptions(array('1'=>_('Yes'),'0'=>_('No')));
		$show_content->setValue('1');
		$show_content->setRequired(true);
		
		$alias = $this->createElement('text', 'alias');
		$alias->setRequired(true);
		$alias->setLabel(_('Alias (short URI):'));
		$alias->addFilter('StringTrim');
		$alias->addFilter('StripTags');
		$alias->setAttrib('maxlength', '32');
		$alias->addValidator('regex', false, array("/^[a-z0-9-_]{2,32}$/i"));
		
		
		$submit = $this->createElement('submit', 'submit')
					   ->setLabel(_('Save'));
					   
		$this->addSubForm($subFormName, 'name');
		$this->addElement($alias);
		$this->addElement($published);
		$this->addElement($show_content);
		$this->addSubForm($subFormDescription, 'description');
		$this->addSubForm($subFormKeywords, 'keywords');
					   
		$this->addElement($submit);
	}
}